package com.mewp.permissions.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mewp.permissions.common.entity.Result;
import com.mewp.permissions.model.po.SysLoginLog;
import com.mewp.permissions.model.vo.SysLoginLogQueryVO;
import com.mewp.permissions.system.service.SysLoginLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author mewp
 * @version 1.0
 * @date 2023/8/5 18:05
 */
@Api(value = "SysLoginLogController", tags = "系统访问管理")
@RestController
@RequestMapping(value = "/admin/system/loginLog")
public class SysLoginLogController {
    @Resource
    private SysLoginLogService loginLogService;

    @ApiOperation(value = "获取分页列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", paramType = "path", required = true),
            @ApiImplicitParam(name = "size", value = "每页记录数", paramType = "path", required = true)
    })
    @GetMapping("{page}/{size}")
    public Result<Page<SysLoginLog>> index(@PathVariable Long page, @PathVariable Long size, SysLoginLogQueryVO sysLoginLogQueryVo) {
        Page<SysLoginLog> pageModel = loginLogService.selectPage(page, size, sysLoginLogQueryVo);
        return Result.ok(pageModel);
    }

    @ApiOperation(value = "获取登录日志记录")
    @GetMapping("/{id}")
    public Result<SysLoginLog> get(@PathVariable Long id) {
        SysLoginLog sysLoginLog = loginLogService.getById(id);
        return Result.ok(sysLoginLog);
    }
}
